//himanshu
#include<malloc.h>
#include<stdio.h>
#include<stdlib.h>

int *a;
int q;
int append(int a[],int w)
	{
	int i;
	printf("Enter the element you to append");
	scanf("%d",&w);
	q=q+1;
	a=realloc(a,sizeof(int)*q);
	a[q-1]=w;
	
	printf("array is:");
		for (i=0;i<q;i++)
		{
		printf("%d ",a[i]);
		}
	}


int inde(int a[],int q)
{
int r,t,i;
printf("Enter the number whose position you want to know");
scanf("%d",&t);
for (i=0;i<q;i++)
{
if(a[i]==t)
{printf("the position is %d",i);
break;
}
}
}

int extend(int a[],int q)
{
int i,y;
printf("Enter the number of elements you want to extend");
scanf("%d",&y);
for(i=q;i<q+y;i++)
{
printf("Enter the elements");
scanf("%d",&a[i]);
}
printf("array is:");
for (i=0;i<q+y;i++)
{
printf("%d",a[i]);
}
}

int insert(int a[],int q)
{
	int u,o,i;
	printf("Enter the position where you want to insert");
	scanf("%d",&u);
	printf("Enter the element");
	scanf("%d",&o);
	q=q+1;
	a=realloc(a,sizeof(int)*q);
	for (i=q;i>u-1;i--)
	{
	a[i]=a[i-1];
	}
	a[u]=o;
	printf("array is:");
	for (i=0;i<q;i++)
	printf("%d ",a[i]);
}


int count(int a[],int q)
{
	int g,count=0,i;
	printf("Enter the number which you want to count");
	scanf("%d",&g);
	for (i=0;i<q;i++)
	{
	if (a[i]==g)
	count=count+1;
	}
	printf("Count=%d",count);
	printf("\n");
}


int remov(int a[],int q)
{
int j,h,i;
printf("Enter the element you want to remove");
scanf("%d",&h);
	for(i=0;i<q;i++)
	{
		if(a[i]==h)
		{
			break;
		
		}
	}
q=q-1;
a=realloc(a,sizeof(int)*q);
for(j=i;j<=q-1;j++)
{
	a[j]=a[j+1];
}

printf("Final Array is:");
for (i=0;i<q;i++)
	{
	printf("%d ",a[i]);
	}
}

int pop(int a[],int q)
{
	int poq,j,i;
	printf("enter the psotion of the element :");
	scanf("%d",&poq);
	q=q-1;
	a=realloc(a,sizeof(int)*q);
for(j=poq;j<=q-1;j++)
{
	a[j]=a[j+1];
}

printf("Final Array is:");
for (i=0;i<q;i++)
{
printf("%d ",a[i]);
}
}
	


int reverse(int a[],int q)
{
int j;
printf("final array is:");
for (j=q-1;j>=0;j--)
{
printf("%d ",a[j]);
}
}



int sort(int a[],int q)
{
	int i,j,k,c;
	for(i=0;i<=q-1;i++)
	{
		for(j=q-1;j>=i+1;j--)
		{
			if(a[j]>a[j+1])
			{
				c=a[j];
				a[j]=a[j+1];
				a[j+1]=c;
			}
		}
	}
		
	for(k=0;k<=q-1;k++)
	{
		printf("%d ",a[k]);
	}
}



void main()
{
int i,n;
printf("Enter the length of array");
scanf("%d",&q);
a=malloc(sizeof(int)*q);

for (i=0;i<q;i++)
{
printf("Enter the elements");
scanf("%d",&a[i]);
}
printf("CHOICES:-\n");
printf("1=append\n");
printf("2=index\n");
printf("3=extend\n");
printf("4=insert\n");
printf("5=pop\n");
printf("6=count\n");
printf("7=remove\n");
printf("8=reverse\n");
printf("9=sort\n");
printf("What do you want to do?\n");
printf("Enter choice:");
scanf("%d",&n);
switch(n){
case 1: append(a,q);
	break;
case 2: inde(a,q);
	break;
case 3: extend(a,q);
	break;
case 4:	insert(a,q);
	break;
case 5: pop(a,q);
	break;
case 6: count(a,q);
	break;
case 7: remov(a,q);
	break;
case 8: reverse(a,q);
	break;
case 9: sort(a,q);
	break;
}
}






